package org.example.service.impl;

import entity.Users;

import lombok.RequiredArgsConstructor;
import org.example.repository.AccountRepository;
import org.example.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AccountServiceImpl implements AccountService {


    private final AccountRepository accountRepository;

    @Override
    public Users findByUsername(String username) {
        return accountRepository.findByUsername(username);
    }

    @Override
    public void updatePassword(String username, String password) {
        Users user = accountRepository.findByUsername(username);
        BCryptPasswordEncoder  passwordEncoder = new BCryptPasswordEncoder(5);
        String pd =  passwordEncoder.encode(password);
        user.setPassword(pd);
        accountRepository.updatePassword(user);
    }
}
